﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using JM.JCY.Common;
using JM.JCY.Common.Utilities;
using System.Web.Security;
using Microsoft.SharePoint.Administration;
using JM.JCY.Proxy;
using JM.JCY.BusinessEntity;
using NCS.IConnect.ApplicationContexts;

namespace JM.JCY.SharePointComponent.IncorruptArchives.PersonImportantReport
{
    public partial class PersonImportantReportUserControl : UserControl
    {
        public string _userName
        {
            set { ViewState["_userName"] = value; }
            get { return (string)ViewState["_userName"]; }
        }

        public string _isApproval
        {
            set { ViewState["_isApproval"] = value; }
            get { return (string)ViewState["_isApproval"]; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (ApplicationContext.Current.UserName != null)
            {
                _userName = ApplicationContext.Current.UserName;
            }
            if (!IsPostBack)
            {
                using (IncorruptProxy proxy = new IncorruptProxy())
                {
                    // load for self
                    _isApproval = "0";
                    this.hfIsApproval.Value = "0";
                    var loadDT = proxy.GetPersonImportantReport(0, _userName);
                    this.gvBC.DataSource = loadDT;
                    this.gvBC.DataBind();

                    // load for approval 
                    //TODO add for approval

                }

            }
        }

        protected void gvBC_DataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                // load date format
                Label lblReportDate = (Label)e.Row.Cells[2].FindControl("lblReportDate");

                string dateString = lblReportDate.Text;
                DateTime dateTime = DateTime.Parse(dateString);
                lblReportDate.Text = dateTime.ToString(JCYConstant.Date_Format_CN);
            }

        }
    }
}
